<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/smoothness/jquery-ui-1.9.0.custom.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.8.0.min.js" type="text/javascript"></script>										<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.9.0.custom.min.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/widgets.js" type="text/javascript"></script>												<!-- 本專案自行定義 JS -->
<script src="js/jquery.checkboxtree.min.js" type="text/javascript"></script>								<!-- CheckBox樹的 JS -->

<title>行帳四科-利用部署代碼部署  </title>

<script type="text/javascript">
function randomSelect(){
	return Math.floor((Math.random()*10)+1);
}

function genOption(tar) {
	var ind = randomSelect();
	for(i=ind;i>0;i--) {
		$("#"+tar).append("<option>"+i+"</option>");
	}
}


function checkDuplicated(grid) {
	var squadId = $("#squadid")[0].value;
	var ll = $("#detailTable_"+grid).jqGrid('getDataIDs');
	var isDuplicated = false;
	for(var i=0;i<ll.length;i++){
		if (ll[i] == squadId ) {
			isDuplicated = true;
		}
	}
	
	if (isDuplicated) {
		alert(squadId+"已經存在，部署小組ID不可重覆 !");
	} else {
		var squadName = $("#squadname")[0].value;
		var dataAdd = {"squadid":squadId,"squadname":squadName,"creator":"842297","createdDateTime":"FFFFFF"};
		var _iCount = $("#detailTable_"+grid).jqGrid('getGridParam', 'records');
		$("#detailTable_"+grid).jqGrid('addRowData', _iCount+1,dataAdd);
	} 
	return [];
}

function buildGrid(grid){
	jQuery("#detailTable_"+grid).jqGrid({
		url:'QuerySquad',
		datatype: "json",
		postData: {
			//getDataType: function() { return "mapping"; },
			tarSys: function() { return "MBMS"; },
			tarSubSys: function() {	return grid; },
			tarEnv: function() { return "QA"; },
		},
		colNames:['部署小組ID', '部署小組名稱','部署路徑','創建人員', '創建日期'],
	   	colModel:[
	   		{name:'squadid',index:'squadid',editable:true,editrules:{required:true}},
	   		{name:'squadname',index:'squadname',editable:true,editrules:{required:true}},
	   		{name:'path',index:'path', edittype:'text',formatter:'text',formatoptions:{disabled:false},editable:true},
	   		{name:'creator',index:'creator'},
	   		{name:'createdDateTime',index:'createdDateTime'}
	   	],
	   	rowNum:10,
	   	loadonce:false,
	   	rowList:[10,20,30],
	   	pager: "#detailPager_"+grid,
		multiselect: false,
		rownumbers: true,
	   	viewrecords: true,
	   	editurl: "ManipulateGridSquad",
		caption:"部署小組所屬的環境",
		onSelectRow: function(ids) {
			jQuery("#masterTable_"+grid).jqGrid('setGridParam',{
				url:"QueryTTT"
			}).trigger('reloadGrid');
		},
		loadComplete: function(data) {
			$("#masterTable_"+grid).jqGrid({
				datatype: "json",
			   	colNames:["<input type='checkbox' onclick='checkBox(event)' />",'環境ID', '環境名稱','創建人員', '創建日期'],
			   	colModel:[
					{name:'my_checkbox',index:'my_checkbox', edittype:"checkbox",
					 formatter: "checkbox", formatoptions: {disabled:false},width:40,align:"center" },
			   		{name:'envid',index:'envid',editable:true, edittype:"text",editrules:{required:true},editoptions: {size:20, maxlength: 20}},
			   		{name:'envname',index:'envname',editable:true, edittype:"text",
			   			editrules:{custom:true,required:true,custom_func:function(){
			   				$("#isNotDuplicated")[0].value = true;
			   				var envId = $("#envid")[0].value;
			   				var envName = $("#envname")[0].value;
			   				var tabIdx = $("#tabsDiv").tabs("option", "selected");
			   				
		   					$("#bssId_form")[0].value = "MBMS";
		   					$("#subSysId_form")[0].value = $("#tab_"+tabIdx).attr("subSys");
		   					$("#envId_form")[0].value = envId;
		   					$.post("IsDuplicated",$("#q_form").serializeArray(),function(res) {
		   						if (res == "true") {
		   							$("#isNotDuplicated")[0].value = false;	
		   						}
		   					},"TEXT");
		   					var rr = $("#isNotDuplicated")[0].value;
							return [rr,"環境ID重複了，換一個!"];
			   			}	// custom_func 結尾
			   		}	//  editrules 結尾
			   		},
			   		{name:'creator',index:'creator'},
			   		{name:'createdDateTime',index:'createdDateTime'}
			   	],
			   	rowNum:10,
			   	pager: "#masterPager_"+grid,
				multiselect: false,
				rownumbers: true,
			   	viewrecords: true,	
				caption: "環境"
			}).jqGrid("navGrid","#masterPager_"+grid,{add:false,edit:false,del:false},
					{},{},{});
		}
	}).navGrid("#detailPager_"+grid,{add:false,edit:false,del:false}
	,{}
	,{}
	,{});
	
	
	
	
	
}

		

$(document).ready(function() {
	
	$("#getDataType")[0].value = "JSON";
	var res =[{"id":"BL","name":"出帳"}];
	$.each(res,function(i, tmp) {
		$("#tabsUlSquad").append("<li><a id=\"tab_"+i+"\" no=\""+i+"\" subSys=\""+tmp.id+"\" href=\"#tab_"+tmp.id+"\">"+tmp.name+" ("+tmp.id+")</a></li>");
		$("#tabsDivSquad").append("<div id=\"tab_"+tmp.id+"\"><table id=\"masterTable_"+tmp.id+"\"></table><div id=\"masterPager_"+tmp.id+"\"></div><p><table id=\"detailTable_"+tmp.id+"\"></table><div id=\"detailPager_"+tmp.id+"\"></div>");
		buildGrid(tmp.id);
	});
		
	$("#tabs").tabs();
	$("#tabs-4").tabs();
	$("#getDataType")[0].value = "";
	
	 
	 $("#grid1").jqGrid({
			url:'QueryReq',
			datatype: "json",
		   	colNames:["需求編號", "需求名稱","創建系統"],
		   	postData: {
				getDataType: function() { return "mappingDep"; },
			},
		   	colModel:[
		   		{name:"reqid",index:"reqid"},
		   		{name:"reqName",index:"reqName"},
		   		{name:"sysFrom",index:"sysFrom"}
		   	],
		   	width:460,
		   	rowNum:20,
		   	pager: "#pager1",
			multiselect: false,
			rownumbers: true,
		   	viewrecords: true,	
			caption: "需求列表"
		});
		jQuery("#grid1").jqGrid("navGrid","#pager1",{add:false,edit:false,del:false});
	
		$("#gridFile").jqGrid({
			datatype: "local",
		   	colNames:["", "版本","路徑","檔名"],
		   	colModel:[
		   		{name:'checkDepFile',index:'checkDepFile', edittype:"checkbox",
				formatter: "checkbox", formatoptions: {disabled:false},width:40,align:"center"},
		   		{name:"ver",index:"ver",width:40},
		   		{name:"pat",index:"pat"},
		   		{name:"fileName",index:"fileName"}
		   	],
		   	width:450,
		   	rowNum:20,
		   	pager: "#pagerFile",
			multiselect: false,
			rownumbers: true,
		   	viewrecords: true,	
			caption: "部署檔案列表"
		}).trigger('reloadGrid');
		jQuery("#gridFile").jqGrid("navGrid","#pagerFile",{add:false,edit:false,del:false});
		
		 var mydata = [
		               {checkDepFile:null,ver:"5",pat:"/gsmsh/bl/month/BL1E00NEW",fileName:"bl1d40.sh"},
		               {checkDepFile:null,ver:"2",pat:"/bms3/gsm/bl2/",fileName:"BL3350NEW.C"},
		               {checkDepFile:null,ver:"7",pat:"/bms3/gsm/bl2/",fileName:"bl3440new.sh"},
		               {checkDepFile:null,ver:"1",pat:"/bms3/gsm/bl3/",fileName:"bl3480new.sh"},
		               {checkDepFile:null,ver:"3",pat:"/bms3/gsm/bl2/",fileName:"BL3750.C"},
		               {checkDepFile:null,ver:"4",pat:"/bms3/gsm/bl2/",fileName:"BL2300NEW_92.sh"},
		               ];
		 for(var i=0;i<=mydata.length;i++)
		 	jQuery("#gridFile").jqGrid('addRowData',i + 1, mydata[i]);
		
		$("button").button();
});
</script>

</head>
<body>
<div id="funcDisplay">
行帳四科-利用部署代碼部署
</div>
<form id="q_form">
	<input type="hidden" id="getDataType" name="getDataType" />
	<input type="hidden" id="bssId_form" name="bssId_form" />
	<input type="hidden" id="subSysId_form" name="subSysId_form" />
	<input type="hidden" id="envId_form" name="envId_form" />
</form>
<input id="subsyses" type="hidden" >
<input id="isNotDuplicated" type="hidden" >

<br/>
<button type="button">部署</button>
<p>

<div id="funcDisplay">
交付流水號：127
</div>
<p>

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">需求列表</a></li>
        <li><a href="#tabs-4">設定欲部署的環境</a></li>
        <li><a href="#tabs-2">設定程式</a></li>
    </ul>
    <div id="tabs-1">
	    <table id="grid1"></table>
		<div id="pager1"></div>
    </div>
    <div id="tabs-4">
        <ul id="tabsUlSquad"></ul>
		<div id="tabsDivSquad"></div>
    </div>
    <div id="tabs-2">
    	<table id="gridFile"></table>
		<div id="pagerFile"></div>
	</div>
</div>



</body>
</html>